package com.andy.qhb.controller.game;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.andy.qhb.base.PageVO;
import com.andy.qhb.base.RespVO;
import com.andy.qhb.controller.GameController;
import com.andy.qhb.controller.UsrGameLogController;
import com.andy.qhb.dao.DaoUtils;
import com.andy.qhb.dao.vo.Where;
import com.andy.qhb.entity.UsrGameLog;
import com.andy.qhb.game.GameUser;
import com.andy.qhb.utils.JsonUtils;

@Controller
@RequestMapping(value="game/api")
public class Api131Controller extends GameController{
	
	private Logger logger = LoggerFactory.getLogger(getClass());
	
	/**
	 * 余额明细
	 * @param session
	 * @param data
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value="131")
	public RespVO action(HttpSession session,String data) throws Exception{
		GameUser user = getUser(session);
		Map<String, Object> reqData = JsonUtils.json2Map(data);
		Integer page = MapUtils.getInteger(reqData, "page",1);
		Integer limit = MapUtils.getInteger(reqData, "limit",20);
		
		PageVO logs = DaoUtils.getPageForMap(UsrGameLog.table(),"id,add_coin/100 as add_coin,result,create_time","id desc",page,limit,Where.eq("uid", user.getId()));
		for(Map<String, Object> item:logs.getItems()){
			item.put("result_desc", UsrGameLogController.ResultDesc[MapUtils.getInteger(item, "result")]);
		}
		return RespVO.createSuccessJsonResonse(logs);
		
	}
	
	
}